/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JTreePanel.java
 *
 * Created on 2010-1-7, 11:13:28
 */

package cn.ekuma.epos.swing.tree;

import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;

/**
 *
 * @author Administrator
 */
public class JTreePanel extends javax.swing.JPanel {

    /** Creates new form JTreePanel */
    public JTreePanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.BorderLayout());

        jTree1.setRootVisible(false);
        jScrollPane1.setViewportView(jTree1);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jSplitPane1.setLeftComponent(jPanel1);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 11", "Item 21", "Item 31", "Item 41", "Item 51", "Item 111", "Item 211", "Item 311", "Item 411", "Item 511" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jList1.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
        jScrollPane2.setViewportView(jList1);

        jPanel2.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jSplitPane1.setRightComponent(jPanel2);

        add(jSplitPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables


    public void setTreeRootNode(MutableTreeNode root){
       jTree1.setModel(new DefaultTreeModel(root));
    }

    public void setListDates(List datas){
        jList1.setListData(datas.toArray());
    }

    public void setToolbar(JPanel bar){
        if(bar!=null)
            add(bar, java.awt.BorderLayout.NORTH);
    }

    public void addTreeSelectionListener(TreeSelectionListener l){
        jTree1.addTreeSelectionListener(l);
    }

    public void removeTreeSelectionListener(TreeSelectionListener l){
        jTree1.removeTreeSelectionListener(l);
    }

    public void addListSelectionListener(ListSelectionListener l){
        jList1.addListSelectionListener(l);
    };

    public void removeListSelectionListener(ListSelectionListener l){
        jList1.removeListSelectionListener(l);
    }

    public void addListMouseListener(MouseListener l){
        jList1.addMouseListener(l);
    }

}
